
function getFile() {
    //注释的代码，有各种测试用例
    function onErrorLoadFs(error) {

    }
    function onErrorCreateFile(error) {

    }
    function onErrorReadFile(error) {

    }

    function displayImage2(imgData) {
        var elem = document.getElementById('imageFile');
        elem.src = imgData;
    }

    function displayImage(blob) {
        // Displays image if result is a valid DOM string for an image.
        var elem = document.getElementById('imageFile');
        // Note: Use window.URL.revokeObjectURL when finished with image.
        elem.src = window.URL.createObjectURL(blob);
    }

    function readBinaryFile(fileEntry) {
        fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function() {
                console.log("Successful file write: " + this.result);
                //displayFileData(fileEntry.fullPath + ": " + this.result);
                var blob = new Blob([new Uint8Array(this.result)], { type: "image/png" });
                displayImage(blob);
                //displayImage2(this.result);
            };
            reader.readAsArrayBuffer(file);
            //reader.readAsDataURL(file);
            //reader.readAsBinaryString(file);
        }, onErrorReadFile);
    }

    function moveToFile(fileEntry, parentDir, newFileName) {
        fileEntry.moveTo(parentDir, newFileName, function(newEntry){
            readBinaryFile(newEntry);
        }, function(error){

        });
    }

    function copyToFile(fileEntry, parentDir, newFileName) {
        fileEntry.copyTo(parentDir, newFileName, function(newEntry){
            readBinaryFile(newEntry);
        }, function(error){

        });
    }

    function readFile(fileEntry) {
        fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function() {
                console.log("Successful file read: " + this.result);
                console.log(fileEntry.fullPath + ": " + this.result);
            };
            reader.readAsText(file);
        }, onErrorReadFile);
    }


    function writeFile(fileEntry, dataObj, isAppend) {
        fileEntry.createWriter(function (fileWriter) {
            fileWriter.onwriteend = function() {
                console.log("Successful file write...");
                window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function(dirEntry) {
                    copyToFile(fileEntry, dirEntry, "newFile.png");
                });
            };
            fileWriter.onerror = function(e) {
                console.log("Failed file write: " + e.toString());
            };
            fileWriter.write(dataObj);
        });
    }

    function saveFile(dirEntry, fileData, fileName) {
        dirEntry.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) {
            writeFile(fileEntry, fileData);
        }, onErrorCreateFile);
    }

    function getSampleFile(dirEntry) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'https://cordova.apache.org/static/img/cordova_bot.png', true);
        xhr.responseType = 'blob';

        xhr.onload = function() {
            if (this.status == 200) {
                var blob = new Blob([this.response], { type: 'image/png' });
                saveFile(dirEntry, blob, "downloadedImage.png");
            }
        };
        xhr.send();
    }

    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        dirEntry.getDirectory("magongshou/import", {create: true}, function (dir) {
            getSampleFile(dir);
        },
        function(){
            return;
        });
    });

    //以下注释代码是其他测试用例，可以参考
    /*
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
        fs.root.getDirectory("yunweibao/easypatrol/import", { create: true, exclusive: false }, function (fileEntry) {
            fileEntry.getDirectory("images", { create: true, exclusive: false }, function (fileEntry) {

            })
            //console.log("fileEntry is file?" + fileEntry.isFile.toString());
            // fileEntry.name == 'someFile.txt'
            // fileEntry.fullPath == '/someFile.txt'
            //writeFile(fileEntry, "chenlh");
        }, onErrorCreateFile);

    }, onErrorLoadFs);
    */
    /*
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        var dirReader = dirEntry.createReader();
        dirReader.readEntries(function(results){
            console.log("Successful file read: " + JSON.stringify(this.result));
        },function(error){

        });
    });
    */

    /*
    window.resolveLocalFileSystemURL("https://localhost/persistent/chuzhitong/downloadedImage.png", function(fileEntry) {
        readBinaryFile(fileEntry);
    });
    */
    /*
    window.resolveLocalFileSystemURL("cdvfile://localhost/persistent/chuzhitong/downloadedImage.png", function(fileEntry) {
        readBinaryFile(fileEntry);
    });
    */
    /*
    window.resolveLocalFileSystemURL("cdvfile://data/storage/el2/base/files/magongshou/import/downloadedImage.png", function(fileEntry) {
        readBinaryFile(fileEntry);
    });*/
}
